package de.iritgo.skillfull.component.visual;

import java.awt.Dimension;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

import de.iritgo.skillfull.collision.CollisionEvent;
import de.iritgo.skillfull.component.VisualComponentImpl;
import de.iritgo.skillfull.component.visitor.PositionVisitor;
import de.iritgo.skillfull.component.visitor.Visitor;
import de.iritgo.skillfull.entity.Entity;
import de.iritgo.skillfull.event.Event;
import de.iritgo.skillfull.event.EventListener;
import de.iritgo.skillfull.event.EventService;

public class SimpleTextComponentImpl extends VisualComponentImpl implements SimpleTextComponent 
{	
	private String text;
	private float timeOnScreen;
	private int nextTick;
	private int duration;
	private float speed;
	private boolean done;

	public void init ()
	{
		done = false;
	}
	
	public void printConfiguration ()
	{
		System.out.println ("     " + toString ());
		System.out.println ("Text on screen: " + scale);
	}

	public void accept (Visitor visitor)
	{
		visitor.visit (this);
	}
	
	public void setScale (float scale)
	{
		this.scale = scale;
	}

	public void showText (String text, float timeOnScreen) 
	{
		this.text = text;
		this.timeOnScreen = timeOnScreen;
		done = false;
		active = true;
	}

	public void setDuration(int duration) 
	{
		this.duration = duration;
	}

	public void setSpeed(float speed) 
	{
		this.speed = speed;
	}

	public void update(GameContainer container, int delta, Entity entity) 
	{
		if (active)
		{
			timeOnScreen = timeOnScreen - delta;
			if (timeOnScreen < 0)
			{
				done = true;
				active = false;
			}
		}
	}
	
	/**
	 * @see de.iritgo.skillfull.component.VisualComponentImpl#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics, de.iritgo.skillfull.entity.Entity)
	 */
	public void render (GameContainer container, Graphics g, Entity entity)
	{
		if (active && timeOnScreen > 0)
		{
			g.drawString (text, x, y);
		}
	}

	@Override
	public boolean isDone() 
	{
		return done;
	}

	@Override
	public void removeText() 
	{
		active = false;
		done = true;
	}
}	
	

